package fourfaith.com.ff_sl21_app.utils.task.model;

import org.apache.commons.lang.StringUtils;

import java.util.LinkedHashMap;
import java.util.Map;


/**
 * 任务--远程设置的类
 * @author administrator
 *
 */
public class TaskDistance {
  
	private String centerAddress;//中心站地址
	
	private String pwd;//通信密码
	
	private String number;//通信号码
	
	private String workModel;//工作模式
	
	private String main1Type;//中心站1主信道类型
	
	private String main1Address;//中心站2主信道地址
	
	private String main2Type;//中心站2主信道类型
	
	private String main2Address;//中心站2主信道地址
	
	private String main3Type;//中心站3主信道类型
	
	private String main3Address;//中心站3主信道地址
	
	private String main4Type;//中心站4主信道类型
	
	private String main4Address;//中心站4主信道地址
	
	private String groupId;//一个标识，分组id或者设备id

	public String getCenterAddress() {
		return centerAddress;
	}

	public void setCenterAddress(String centerAddress) {
		this.centerAddress = centerAddress;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getWorkModel() {
		return workModel;
	}

	public void setWorkModel(String workModel) {
		this.workModel = workModel;
	}

	public String getMain1Type() {
		return main1Type;
	}

	public void setMain1Type(String main1Type) {
		this.main1Type = main1Type;
	}

	public String getMain1Address() {
		return main1Address;
	}

	public void setMain1Address(String main1Address) {
		this.main1Address = main1Address;
	}

	public String getMain2Type() {
		return main2Type;
	}

	public void setMain2Type(String main2Type) {
		this.main2Type = main2Type;
	}

	public String getMain2Address() {
		return main2Address;
	}

	public void setMain2Address(String main2Address) {
		this.main2Address = main2Address;
	}

	public String getMain3Type() {
		return main3Type;
	}

	public void setMain3Type(String main3Type) {
		this.main3Type = main3Type;
	}

	public String getMain3Address() {
		return main3Address;
	}

	public void setMain3Address(String main3Address) {
		this.main3Address = main3Address;
	}

	public String getMain4Type() {
		return main4Type;
	}

	public void setMain4Type(String main4Type) {
		this.main4Type = main4Type;
	}

	public String getMain4Address() {
		return main4Address;
	}

	public void setMain4Address(String main4Address) {
		this.main4Address = main4Address;
	}

	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}
	
	
	/**
	 * 根据字符串构造model
	 * @param disStr 中心返回的result str
	 * @return
	 */
	public static TaskDistance getTaskDistanceByStr(String disStr) {

		TaskDistance distance = new TaskDistance();
		if (StringUtils.isNotEmpty(disStr)) {
			String[] strSplit = disStr.split("\\r");
			for (int i = 0; i < strSplit.length; i++) {
				String[] split = strSplit[i].split("_");
				switch (split[0]) {
				case "01":
					if (split.length > 1) {
						distance.setCenterAddress(split[1]);
					} else {
						distance.setCenterAddress("");
					}
					break;
				case "03":
					if (split.length > 1) {
						distance.setPwd(split[1]);
					} else {
						distance.setPwd("");
					}
					break;
				case "0F":
					if (split.length > 1) {
						String[] sp = split[1].split("\\^");
						if (sp.length > 1) {
							distance.setNumber(sp[1]);
						} else {
							distance.setNumber("");
						}
					} else {
						// distance.setNumber("未接入");
						distance.setNumber("");
					}
					break;
				case "0C":
					if (split.length > 1) {
						distance.setWorkModel(split[1]);
					} else {
						distance.setWorkModel("");
					}
					break;
				case "04":
					if (split.length > 1) {
						String[] sp = split[1].split("\\^");
						if (sp.length > 0) {
							distance.setMain1Type(sp[0]);
							if (sp.length > 1) {
								distance.setMain1Address(sp[1]);
							} else {
								distance.setMain1Address("");
							}
						}
					} else {
						// 为空的情况
						distance.setMain1Address(split[1]);
						distance.setMain1Type(split[1]);
					}
					break;
				case "06":
					if (split.length > 1) {
						String[] sp = split[1].split("\\^");
						if (sp.length > 0) {
							distance.setMain2Type(sp[0]);
							if (sp.length > 1) {
								distance.setMain2Address(sp[1]);
							} else {
								distance.setMain2Address("");
							}
						}
					} else {
						// 为空的情况
						distance.setMain2Address(split[1]);
						distance.setMain2Type(split[1]);
					}
					break;
				case "08":
					if (split.length > 1) {
						String[] sp = split[1].split("\\^");
						if (sp.length > 0) {
							distance.setMain3Type(sp[0]);
							if (sp.length > 1) {
								distance.setMain3Address(sp[1]);
							} else {
								distance.setMain3Address("");
							}
						}
					} else {
						// 为空的情况
						distance.setMain3Address(split[1]);
						distance.setMain3Type(split[1]);
					}
					break;
				case "0A":
					if (split.length > 1) {
						String[] sp = split[1].split("\\^");
						if (sp.length > 0) {
							distance.setMain4Type(sp[0]);
							if (sp.length > 1) {
								distance.setMain4Address(sp[1]);
							} else {
								distance.setMain4Address("");
							}
						}
					} else {
						// 为空的情况
						distance.setMain4Address(split[1]);
						distance.setMain4Type(split[1]);
					}
					break;
				default:
					break;
				}
			}
		}

		return distance;
	}
	
	/**
	 * 根据字符串构造model
	 * @param disStr 中心返回的result str
	 * @return
	 */
	public static Map<Integer, String> getTypeMap(){
		Map<Integer, String> map = new LinkedHashMap<Integer, String>();
		
		map.put(0, "禁用");
		map.put(1, "短信");
		map.put(2, "IPV4");
		map.put(3, "北斗");
		map.put(4, "海事卫星");
		map.put(5, "PSTN");
		map.put(6, "超短波");
		
		return map;
	}
}
